package com.indusfo.spc.config;

import com.indusfo.spc.interceptor.AuthenticationInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.validation.MessageCodesResolver;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.config.annotation.*;

import java.util.List;

/**
 * @author chenm
 * @create 2019-11-29 13:43
 */
@Configuration
public class MyWebAppConfigurer implements WebMvcConfigurer {

  @Autowired
  private AuthenticationInterceptor authenticationInterceptor;

    /**
     * @author chenm
     * @create 2019-11-29 13:43
     * 资源映射路径
     */
  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
    /** 本地文件上传路径 */
    registry.addResourceHandler("/upload/**").addResourceLocations("file:///" + PieceFlowConfig.getProfile() + "/");
  }

    /**
     * @author chenm
     * @create 2019-11-29 13:43
     * 自定义拦截规则
     */
  @Override
  public void addInterceptors(InterceptorRegistry registry) {

//        addPathPatterns添加需要拦截的命名空间；
//        excludePathPatterns添加排除拦截命名空间
      registry.addInterceptor(authenticationInterceptor).addPathPatterns("/**").excludePathPatterns("/register");;
  }

  @Bean
  public AuthenticationInterceptor authenticationInterceptor() {
    return new AuthenticationInterceptor();
  }


  }
